﻿using Abp.Domain.Entities.Auditing;
using Mt.Site.Core.WorkFlows.Enum;
using System;
using System.ComponentModel.DataAnnotations;

namespace Mt.Site.Core.WorkFlows.Process.Entities
{
    /// <summary>
    /// 操作记录
    /// </summary>
    public class WorkFlowProcess : AuditedEntity<Guid>
    {
        public const int MaxReplyLength = 2000;

        public const string DefaultReplyMsg = "";//"已办理！";

        public const int MaxUserInfoDtoJsonLength = 2000;
        public const int MaxCustomDataLength = 1024 * 2;
        public const int MaxFormDataCacheLength = 1024 * 4;
        /// <summary>
        /// 所属流程
        /// </summary>
        public Guid WorkFlowId { get; set; }

        /// <summary>
        /// 当前所处步骤
        /// </summary>
        public Guid NodeId { get; set; }


        public long UserId { get; set; }

        [MaxLength(64)]
        public string UserName { get; set; }

        /// <summary>
        /// Save用户当时的UserInfoDto作为快照，用户的信息可能在表单布局中使用，但用户岗位是可能调整的
        /// </summary>
        [MaxLength(MaxUserInfoDtoJsonLength)] 
        public string UserInfoDtoJson { get; set; }

        public Guid PaperId { get; set; }

        public ActionState State { get; set; }

        /// <summary>
        /// 已阅
        /// </summary>
        public bool HasMarked { get; set; }

        /// <summary>
        /// 查看时间
        /// </summary>
        public DateTime? MarkedTime { get; set; }


        [StringLength(MaxReplyLength)]
        public string Reply { get; set; }

        /// <summary>
        /// 最后一次回应时间
        /// </summary>
        public DateTime? ReplyTime { get; set; }

        /// <summary>
        /// 办理时间
        /// </summary>
        public DateTime? FinishedTime { get; set; }

        /// <summary>
        /// null:主线，!=null:发起分支路线的那条数据的id
        /// </summary>
        public Guid? TrunkId { get; set; }

        /// <summary>
        /// 上一个操作者对应的数据id（创建这条任务的上一个任务操作者）
        /// </summary>
        public Guid? PreStepId { get; set; }

        /// <summary>
        /// 前一个操作者的数据ID （修改这条任务数据状态State的上一个任务操作者）
        /// </summary>
        public Guid? PreOperatorId { get; set; }

        public ActionScheme ActionScheme { get; set; }

        /// <summary>
        /// 任务下达时间
        /// </summary>
        public DateTime StartTime { get; set; }

        public bool IsDefaultMsg { get; set; }

        [MaxLength(300)]
        public string Code { get; set; }

        public int StepCode { get; set; }

        public MoveMode MovePattern { get; set; }

        public OperationType OperationType { get; set; }

        public bool HasRead { get; set; }

        [StringLength(2000)]
        public string WaitingList { get; set; }

        public Guid? ResponsibilityId { get; set; }

        public Guid? FinishedByTheWay { get; set; }

        public bool Parallel { get; set; }

        public Guid? EndNodeId { get; set; }

        /// <summary>
        /// 用于做一些自定义标记，为后续的操作传递一些判别条件等
        /// </summary>
        [StringLength(300)]
        public string Signal { get; set; }

        /// <summary>
        /// 用于做一些自定义标记，为后续的操作传递一些判别条件等
        /// </summary>
        [StringLength(300)]
        public string Signal2 { get; set; }

        /// <summary>
        /// 类似Signal字段 ，用于存放一些自定义数据
        /// </summary>
        [StringLength(MaxCustomDataLength)]
        public string CustomData { get; set; }

        public bool IsHiddenInTable { get; set; }

        /// <summary>
        ///优先级 目前只对待办任务设置优先级
        /// </summary>
        public WorkFlowOpSeverity Severity { get; set; }

        /// <summary>
        /// 表单数据备份（具体使用方法参考运河oa） ，后期看是否需要移到一个独立的日志表中（同时备份大字段（eg:富文本））
        /// </summary>
        [StringLength(MaxFormDataCacheLength)]
        public string FormDataCache { get; set; }

        public bool CanEditForm { get; set; }
    }
}
